#include "return_json_object.h"
#include "json/json.h"
using namespace std;


Json::Value RetFaceAttr::Convert2JsonValue() 
{
    
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

    Json::Value  data;
    data["age"] = attr.age;
	data["expression"] = attr.expression;
	data["expression_conf"] = attr.expression_conf;
	data["gender"] = attr.gender;
	data["gender_conf"] = attr.gender_conf;
	data["glass"] = attr.glass;
	data["glass_conf"] = attr.glass_conf;
	data["race"] = attr.race;
	data["race_conf"] = attr.race_conf;

    valueinfo["data"] = data;

	return valueinfo;
}


Json::Value RetFaceQuality::Convert2JsonValue() 
{
    
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

    Json::Value  data;
    data["bluriness"] = quality.bluriness;
    data["illum"] = quality.illum;
    data["occl_chin"] = quality.occl_chin;
    data["occl_l_contour"] = quality.occl_l_contour;
    data["occl_l_eye"] = quality.occl_l_eye;
    data["occl_mouth"] = quality.occl_mouth;
    data["occl_nose"] = quality.occl_nose;
    data["occl_r_contour"] = quality.occl_r_contour;
    data["occl_r_eye"] = quality.occl_r_eye;
   
	valueinfo["data"] = data;

	return valueinfo;
}


Json::Value RetFaceInfo::Convert2JsonValue()
{
	Json::Value valueinfo;
	valueinfo["x"] = x;
	valueinfo["y"] = y;
	valueinfo["width"] = width;
	valueinfo["height"] = height;
	valueinfo["img"] = img;
	return valueinfo;
}


int RetMultFaceTrackInfo::AddFaceInfo(const RetFaceInfo& info)
{
	retFaceImg = true;
	count++;
	faces.push_back(info);
}


Json::Value RetMultFaceTrackInfo::Convert2JsonValue()
{
    
    Json::Value  valueinfo;
    valueinfo["code"] = code;   
    valueinfo["message"] = message;

	Json::Value valuefaces;
    for(uint32_t i =0; i < faces.size(); ++i) {
		valuefaces.append(faces[i].Convert2JsonValue());
	}
 
	Json::Value  data;
	data["count"] = count;
	data["faces"] = valuefaces;
	data["retFaceImg"] = true;
	
	valueinfo["data"] = data;
 
    return valueinfo;
}


Json::Value RetFaceFeature::Convert2JsonValue()
{
    
    Json::Value  valueinfo;
    valueinfo["code"] = code;   
    valueinfo["message"] = message;

	Json::Value valuefeatures;
    for(uint32_t i =0; i < features.size(); ++i) {
		valuefeatures.append(features[i]);
	}
 
	Json::Value  data;

	data["features:"] = valuefeatures;
		
	valueinfo["data"] = data;
 
    return valueinfo;
}


Json::Value RetMatchFace::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

    Json::Value  data;
    data["score"] = score;
    valueinfo["data"] = data;

	return valueinfo;

}

Json::Value RetRegisterFace::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

    //Json::Value  data;
    //data["score"] = score;
    //valueinfo["data"] = ;

	return valueinfo;
}


Json::Value RetSearchFace::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

    Json::Value  data;
    data["score"] = score;
	data["faceKey"] = face_key;
	data["faceId"] = face_id;
    valueinfo["data"] = data;

	return valueinfo;

}


Json::Value RetMultSearchFace::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;


	map<string,search_return_t>::iterator it;
	for( it = searched.begin(); it != searched.end(); ++it){
    
		Json::Value  data;
		data["score"] = it->second.score;
		data["faceKey"] = it->second.face_key;
		data["faceId"] = it->second.face_id;
		data["imgName"] = it->first;
		valueinfo["data"].append(data);
	}

	return valueinfo;

}


Json::Value RetRemoveFace::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

	return valueinfo;
}


Json::Value RetClearFaces::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

	return valueinfo;
}


Json::Value RetNoHandler::Convert2JsonValue()
{
    Json::Value  valueinfo;

    valueinfo["code"] = code;   
    valueinfo["message"] = message;

	return valueinfo;
}


std::string Serialize(shared_ptr<BaseObjectIf> object)
{
	Json::Value value = object->Convert2JsonValue();
	Json::FastWriter writerinfo;
	return writerinfo.write(value);
}

